﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;

namespace sunsetmp.DialogWindow
{
    /// <summary>
    /// Interaction logic for DownloadQuestionWindow.xaml
    /// </summary>
    public partial class DownloadQuestionWindow : Window
    {
        string track_url = null;
        string track_name = null;
        DownloadWindow DW;
        Properties.Settings ps = Properties.Settings.Default;

        public DownloadQuestionWindow(DownloadWindow dw)
        {
            DW = dw;
            WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            InitializeComponent();
            this.Icon = new BitmapImage(new Uri(Directory.GetCurrentDirectory().ToString() + @"/Themes/Icons/Logo.ico"));
        }

        public void Request(string url, string name)
        {
            track_name = name;
            track_url = url;
            this.Label.Content = "Файл " + name;
            this.Show();
        }

        private void Grid_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        private void CloseW_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
            DW.Close();
        }

        private void DelButton_Click(object sender, RoutedEventArgs e)
        {
            File.Delete(@ps.downDir + track_name);
            DW.DownloadTrack(track_url, track_name);
            this.Close();
        }

        private void CopyButton_Click(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < 300; i++)
            {
                if (!File.Exists(@ps.downDir + track_name + "_" + i.ToString()))
                {
                    DW.DownloadTrack(track_url, track_name + "_" + i.ToString());
                    break;
                }
            }
            this.Close();
        }

        private void NothingButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
            DW.Close();
        }

        private void Window_StateChanged_1(object sender, System.EventArgs e)
        {
            if (this.WindowState == System.Windows.WindowState.Maximized)
                this.WindowState = System.Windows.WindowState.Normal;
        }
    }
}
